<template>
  <view class="custom-checkbox" :class="{ 'checkbox-checked': value }" @click="hanldeCheck">
    <view class="checkbox-inner"></view>
    <view class="checkbox-text">
      <slot></slot>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      checked: this.value,
    };
  },
  mounted() {},
  methods: {
    hanldeCheck() {
      this.checked = !this.checked;
      this.$emit("input", this.checked);
      this.$emit("onChecked", this.checked);
    },
  },
  watch: {
    value(checked) {
      this.checked = checked;
    },
  },
};
</script>

<style lang="scss" scoped>
.custom-checkbox {
  // width: 100%;
  // height: 24px;
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 14px;

  .checkbox-inner {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border: 1px solid #909399;
    border-radius: 2px;
    position: relative;
    // display: inline-block;
    // vertical-align: middle;
    margin-right: 8px;
  }

  .checkbox-text {
    width: 100%;
    box-sizing: border-box;
    // vertical-align: middle;
  }
}

.checkbox-checked .checkbox-inner::after {
  content: "";
  display: table;
  box-sizing: border-box;
  top: 50%;
  width: 6px;
  height: 10px;
  position: absolute;
  border: 2px solid #3a8ee6;
  border-top: 0;
  border-inline-start: 0;
  inset-inline-start: 21.5%;
  transform: rotate(45deg) scale(1) translate(-50%, -50%);
  transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;
}
</style>
